package com.csq.androidproject.views.calendarview.caldroid.adapters;

import java.util.ArrayList;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;

import com.csq.androidproject.views.calendarview.caldroid.views.CalendarView;
import com.csq.androidproject.views.calendarview.caldroid.views.PageGridView;

/**
 * MonthPagerAdapter holds 4 fragments, which provides fragment for current
 * month, previous month and next month. The extra fragment helps for recycle
 * fragments.
 */
public class MonthPagerAdapter extends PagerAdapter {

    private Context context;
	private ArrayList<PageGridView> items;

	// Lazily create the fragments
	public ArrayList<PageGridView> getItems() {
		if (items == null) {
		    items = new ArrayList<PageGridView>();
			for (int i = 0; i < getCount(); i++) {
			    items.add(new PageGridView(context));
			}
		}
		return items;
	}

	public void setItems(ArrayList<PageGridView> items) {
		this.items = items;
	}

	public MonthPagerAdapter(Context context) {
	    this.context = context;
	}
	
	@Override
	public Object instantiateItem(ViewGroup container, int position) {
	    // TODO Auto-generated method stub
	    View view = items.get(position);
        container.addView(view);
        return view;
	}
	
	@Override
	public void destroyItem(ViewGroup container, int position, Object object) {
	    // TODO Auto-generated method stub
	    container.removeView(items.get(position));
	}
	
    @Override
    public boolean isViewFromObject(View arg0, Object arg1) {
        // TODO Auto-generated method stub
        return arg0 == arg1;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return CalendarView.NUMBER_OF_PAGES;
    }

}
